<script>
	import { AccountInfoService } from '@/services/security/AccountInfo';
	import store from '@/store';

	export default {
		name: 'Authority',
		functional: true,
		props: {
			roles: {
				type: Array,
				default: function() {
					return [];
				}
			},
			accesses: {
				type: Array,
				default: function() {
					return [];
				}
			}
		},
		render(h, context) {
			const { props, scopedSlots } = context;
			// 如果校验通过，则返回子组件/插槽内容；否则返回null;
			return AccountInfoService.isAllowed(
				props.roles,
				props.accesses,
				store.getters.info
			)
				? scopedSlots.default()
				: null;
		}
	};
</script>
